define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'pay/order/index' + location.search,
                    // add_url: 'pay/order/add',
                    // edit_url: 'pay/order/edit',
                    // del_url: 'pay/order/del',
                    // multi_url: 'pay/order/multi',
                    // import_url: 'pay/order/import',
                    table: 'pay_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'po_id',
                sortName: 'po_id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'po_id', title: __('Po_id'),visible:false},
                        {field: 'order', title: __('Order'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'user_id', title: __('User_id'),visible:false},
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        {field: 'pay_state', title: __('Pay_state'), searchList: {"0":__('Pay_state 0'),"1":__('Pay_state 1'),"2":__('Pay_state 2'),"3":__('Pay_state 3'),"4":__('Pay_state 4')}, formatter: Table.api.formatter.normal},
                        {field: 'order_money', title: __('Order_money'), operate:'BETWEEN'},
                        {field: 'pref_money', title: __('Pref_money'), operate:'BETWEEN'},
                        {field: 'trilateral_pay_order', title: __('Trilateral_pay_order'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'pay_date', title: __('Pay_date')},
                        {field: 'cancel_date', title: __('Cancel_date')},
                        {field: 'pc_id', title: __('Pc_id')},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3'),"4":__('Type 4')}, formatter: Table.api.formatter.normal},
                        {field: 'relation_id', title: __('Relation_id')},
                        {field: 'ct_date', title: __('Ct_date')},
                        {field: 'up_date', title: __('Up_date')},
                        {field: 'trilateral_pay_order',title:'余额支付',operate:false,formatter:function (row,value) {
                            if (value.pay_state == 1) {
                                if (value.trilateral_pay_order){
                                    return '<b style="color:deepskyblue">否<b>';
                                }else{
                                    return '<b style="color:indianred">是<b>';
                                }
                            }

                            }},
                        {field: 'delete', title: __('Delete'), searchList: {"0":__('Delete 0'),"1":__('Delete 1')}, formatter: Table.api.formatter.normal},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
